using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace MIS.EN.Exchange.Entities
{
    /// <summary>
    /// Factory class for building <see cref="MIS.EN.Exchange.Entities.Item"/> instances.
    /// </summary>
    public static class EntityFactory
    {
        private static Assembly executingAssembly;

        static EntityFactory()
        {
            EntityFactory.executingAssembly = Assembly.GetExecutingAssembly();
        }

        /// <summary>
        /// Given the type, builds the correct <see cref="MIS.EN.Exchange.Entities.Item"/>.
        /// </summary>
        /// <param name="type">The <see cref="System.Type"/> to build.</param>
        /// <returns>An <see cref="MIS.EN.Exchange.Entities.Item"/> instance.</returns>
        public static Item BuildEntity(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            Item item = null;
            item = EntityFactory.executingAssembly.CreateInstance(type.FullName, true) as Item;
            return item;
        }
    }
}
